//
//  LiveTableViewCell.m
//  BasketballClub
//
//  Created by lanou3g on 16/1/6.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "LiveTableViewCell.h"

#import "LiveHandle.h"
#import "LiveModel.h"
#import <UIImageView+WebCache.h>

@implementation LiveTableViewCell

#pragma mark  -  重写 cell的初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self allViews];
    }
    return self;
}
#pragma mark - 布局子视图
-(void)allViews
{

    
    
    //客队logo布局
    self.player1LogoImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    self.player1LogoImage.frame = CGRectMake(50*LAYOUT_SIZE, 40*LAYOUT_SIZE_HEIGHT, 70*LAYOUT_SIZE, 70*LAYOUT_SIZE_HEIGHT);
    
    [self.contentView addSubview:self.player1LogoImage];
    //客队名称
    self.player1Label = [[UILabel alloc]initWithFrame:CGRectMake(50*LAYOUT_SIZE, 115*LAYOUT_SIZE_HEIGHT, 70*LAYOUT_SIZE, 20*LAYOUT_SIZE_HEIGHT)];
    
    self.player1Label.textAlignment = NSTextAlignmentCenter;
    self.player1Label.font = [UIFont systemFontOfSize:15*LAYOUT_SIZE];
    [self.contentView addSubview:self.player1Label];
    //主队队logo布局
    self.player2LogoImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];

    self.player2LogoImage.frame = CGRectMake(SCREEN_WIDTH - 120*LAYOUT_SIZE,  40*LAYOUT_SIZE_HEIGHT, 70*LAYOUT_SIZE, 70*LAYOUT_SIZE_HEIGHT);
    
    [self.contentView addSubview:self.player2LogoImage];
    //主队名称
    self.player2Label = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 120*LAYOUT_SIZE, 115*LAYOUT_SIZE_HEIGHT, 70*LAYOUT_SIZE, 20*LAYOUT_SIZE_HEIGHT)];
    self.player2Label.textAlignment = NSTextAlignmentCenter;
    self.player2Label.font = [UIFont systemFontOfSize:15*LAYOUT_SIZE];
    [self.contentView addSubview:self.player2Label];
    //比分
    self.scoreLabel =[[UILabel alloc]initWithFrame:CGRectMake(80*LAYOUT_SIZE, 15*LAYOUT_SIZE_HEIGHT, 254*LAYOUT_SIZE, 25*LAYOUT_SIZE_HEIGHT)];
    self.scoreLabel.textAlignment = NSTextAlignmentCenter;
    self.scoreLabel.font = [UIFont systemFontOfSize:23*LAYOUT_SIZE];
    [self addSubview:self.scoreLabel];
    //视频或文字直播button
    self.videoOrTextBtn = [[UIButton alloc]initWithFrame:CGRectMake(155*LAYOUT_SIZE, 50*LAYOUT_SIZE_HEIGHT, 104*LAYOUT_SIZE, 20*LAYOUT_SIZE_HEIGHT)];
    self.videoOrTextBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15*LAYOUT_SIZE];
    self.videoOrTextBtn.titleLabel.textColor  = [UIColor redColor];
    self.videoOrTextBtn.backgroundColor = [UIColor colorWithRed:100/255.0 green:200/255.0 blue:244/255.0 alpha:1];
    [self.videoOrTextBtn addTarget:self action:@selector(videoOrTextBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.videoOrTextBtn];
    //技术统计按钮
    self.countBtn = [[UIButton alloc]initWithFrame:CGRectMake(155*LAYOUT_SIZE, 85*LAYOUT_SIZE_HEIGHT, 104*LAYOUT_SIZE, 20*LAYOUT_SIZE_HEIGHT)];
    self.countBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15*LAYOUT_SIZE];
    self.countBtn.backgroundColor = [UIColor redColor];
    self.countBtn.titleLabel.textColor  = [UIColor redColor];
    [self.countBtn addTarget:self action:@selector(countBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.countBtn];
    //比赛时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(80*LAYOUT_SIZE, 140*LAYOUT_SIZE_HEIGHT, 127*LAYOUT_SIZE, 30*LAYOUT_SIZE_HEIGHT)];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.font = [UIFont systemFontOfSize:15*LAYOUT_SIZE];
    [self.contentView addSubview:self.timeLabel];
    //比赛状态
    self.statusLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-177*LAYOUT_SIZE, 140*LAYOUT_SIZE_HEIGHT, 80*LAYOUT_SIZE, 30*LAYOUT_SIZE_HEIGHT)];
    self.statusLabel.textAlignment = NSTextAlignmentCenter;
    self.statusLabel.font = [UIFont systemFontOfSize:15*LAYOUT_SIZE];
    
    [self.contentView addSubview:self.statusLabel];
    
       
}
#pragma mark - 视频/文字直播
-(void)videoOrTextBtnDidClicked:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(LiveTableViewCellVideoOrTextBtnDidClicked:)]) {
        [self.delegate LiveTableViewCellVideoOrTextBtnDidClicked:self];
    }
    
}

#pragma mark - 技术统计
-(void)countBtnDidClicked:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(LiveTableViewCellCountBtnDidClicked:)]) {
        [self.delegate LiveTableViewCellCountBtnDidClicked:self];
    }
    
    
    
}

#pragma mark - cell赋值
-(void)setCellDataFromLiveModel:(LiveModel *)model
{
    //判断比赛的状态
    if (model.status==0) {
        
        self.statusLabel.text = @"未开赛";
        
        self.statusLabel.textColor = [UIColor whiteColor];
        
        self.statusLabel.backgroundColor = [UIColor colorWithRed:30 / 255.0 green:144 / 255.0 blue:255 / 255.0 alpha:0.3];
        self.countBtn.userInteractionEnabled = NO;
        self.countBtn.alpha = 0.4;
    }else if (model.status == 1){
        self.statusLabel.text = @"直播中";
        self.statusLabel.textColor = [UIColor whiteColor];
        self.statusLabel.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:0 blue:0 alpha:1];
        self.countBtn.userInteractionEnabled = YES;
        self.countBtn.alpha = 1;

    }else{
        self.statusLabel.text = @"已结束";
     
        self.statusLabel.textColor = [UIColor whiteColor];
        self.statusLabel.backgroundColor = [UIColor lightGrayColor];
        self.countBtn.userInteractionEnabled = YES;
        self.countBtn.alpha = 1;
    

    }
    
    
    //客队logo
    [self.player1LogoImage sd_setImageWithURL:[NSURL URLWithString:model.player1logo]];
    //主队logo
    [self.player2LogoImage sd_setImageWithURL:[NSURL URLWithString:model.player2logo]];
    //客队名
    self.player1Label.text = model.player1;
    //主队名
    self.player2Label.text = model.player2;
    
   //比分情况
    self.scoreLabel.text = model.score;
    //比赛时间
    self.timeLabel.text = model.time;
    //视频或文字直播按钮
    [self.videoOrTextBtn setTitle:model.link1text forState:UIControlStateNormal];
    //计数统计按钮
    [self.countBtn setTitle:model.link2text forState:UIControlStateNormal] ;
    
    
    
}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
